package com.lcl.jarvis.controller;

import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lcl.jarvis.util.Result;

import com.lcl.jarvis.dto.EpidemiologicalInfoDTO;
import com.lcl.jarvis.dto.EpidemiologicalInfoQueryDTO;
import com.lcl.jarvis.service.EpidemiologicalInfoService;
import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author licl
 * @since 2024-05-16
 */
@RestController
@Slf4j
@Api(value = "/web/business/epidemiologicalInfo", tags = {"流行病学信息采集操作接口"})
@RequestMapping("/web/business/epidemiologicalInfo")
public class EpidemiologicalInfoController {


    private final EpidemiologicalInfoService epidemiologicalInfoService;

    @Autowired
    public EpidemiologicalInfoController(EpidemiologicalInfoService epidemiologicalInfoService){
        this.epidemiologicalInfoService = epidemiologicalInfoService;
    }
    /**
     * 通过ID查询
     *
     * @param id ID
     * @return EpidemiologicalInfo
     */
    @ApiOperation(value = "通过ID查询", tags = {"通过ID查询"}, notes = "ID不能为空")
    @GetMapping("/{id}")
    public Result<EpidemiologicalInfoDTO> get(@PathVariable String id) {
        return Result.ok(epidemiologicalInfoService.queryById(id));
    }

    /**
     * 分页查询信息
     *
     * @param epidemiologicalInfoQuery 分页对象
     * @return 分页对象
     */
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "pageNumber", value = "页码", dataType = "string", paramType = "query", example = "1"),
        @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "long", paramType = "query", example = "10"),
        @ApiImplicitParam(name = "sort", value = "正序/倒序", dataType = "string", paramType = "query", example = "asc/desc"),
        @ApiImplicitParam(name = "order", value = "排序字段-属性名", dataType = "string", paramType = "query", example = "rid"),
        @ApiImplicitParam(name = "epidemiologicalInfo", value = "查询条件", dataType = "EpidemiologicalInfoQueryDTO", paramType = "query")
    })
    public Result<Map<String, Object>> page(EpidemiologicalInfoQueryDTO epidemiologicalInfoQuery) {
        Map<String, Object> map = epidemiologicalInfoService.queryPage(epidemiologicalInfoQuery);
    	// 如不想动BO，此处可以再加工为前台需要的自定义对象，适配界面用，例如 (**DTO)map.get("result")
    	return Result.ok(map);
    }

    /**
     * 添加
     *
     * @param epidemiologicalInfo 实体
     * @return success/false
     */
    @PostMapping
    @ApiOperation(value = "添加")
    @ResponseStatus(HttpStatus.CREATED)
    public Result<?> add(@Valid @RequestBody @ApiParam(name="",value="传入json格式",required=true) EpidemiologicalInfoDTO epidemiologicalInfoDto) {
        EpidemiologicalInfoDTO EpidemiologicalInfoDto = epidemiologicalInfoService.save(epidemiologicalInfoDto);
        return Result.ok(EpidemiologicalInfoDto);
    }

    /**
     * 删除
     *
     * @param id ID
     * @return success/false
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public Result<?>  delete(@PathVariable String id) {
        epidemiologicalInfoService.delete(id);
        return Result.ok("");
    }

    /**
     * 编辑
     *
     * @param epidemiologicalInfo 实体
     * @return success/false
     */
    @PutMapping
    @ApiOperation(value = "编辑")
    @ResponseStatus(HttpStatus.ACCEPTED)
    public Result<?> edit(@Valid @RequestBody @ApiParam(name="",value="传入json格式",required=true) EpidemiologicalInfoDTO epidemiologicalInfoDto) {
        EpidemiologicalInfoDTO EpidemiologicalInfoDto = epidemiologicalInfoService.update(epidemiologicalInfoDto);
        return Result.ok(EpidemiologicalInfoDto);
    }
}
